package main.java.tmi.actualStockStatus.web;

import java.sql.SQLException;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import main.java.tmi.actualStockStatus.service.ActualStockStatusService;
import main.java.tmi.common.service.UserVO;
import main.java.tmi.common.util.AjaxPageSplit;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;


/**
 *  Controller
 *
 * @author min™
 * @since 2012. 05. 08.
 */
@Controller
public class ActualStockStatusController {
	
    @Resource(name = "actualStockStatusServiceImpl")
    private ActualStockStatusService actualStockStatusService;
    
    /**
     * The Constructor
     */
    public ActualStockStatusController() {
        //logger = LogFactory.getLog(this.getClass());
    }

    /**
     * 
     * 
     * @param HttpServletResponse response
     * @param ModelMap model
     * @return
     * @throws SQLException
     */
    @RequestMapping("/actualStockStatus")
    public String viewList(HttpServletRequest request, HttpServletResponse response,
            ModelMap model) throws SQLException {
        System.out.println("====================================================");
        System.out.println("===============actualStockStatus start=========================");
        System.out.println("====================================================");
        UserVO userInfo = (UserVO) RequestContextHolder.getRequestAttributes().getAttribute("userInfo", RequestAttributes.SCOPE_SESSION);
		model.addAttribute("custCodeUser",userInfo.getCustCode());
		model.addAttribute("roleId",userInfo.getRoleId());
        return "/tmi/actualStockStatus/actualStockStatus";
    }
    
    
    
    /**
     * search
     * 
     * @param HttpServletResponse response
     * @param ModelMap model
     * @return
     * @throws SQLException
     */
    
    @RequestMapping("/getActualStockStatusView")
    public void getActualStockStatusView(@RequestParam Map param, Model model) throws Exception {
        System.out.println("=======================> getActualStockStatusView start");
        AjaxPageSplit pageSplitMgr = new AjaxPageSplit();
        int pagingTmp = Integer.parseInt(param.get("paging").toString());
		int listScale = Integer.parseInt(param.get("listScale").toString());
		int paging = (pagingTmp-1)*listScale;
		param.put("paging", paging);
        int actualStockStatusCount = actualStockStatusService.getActualStockStatusViewCount(param);
		String pageSplit = pageSplitMgr.getSplitPageLink(actualStockStatusCount, pagingTmp, listScale, 5, "");
		System.out.println("===========pageSplit============> "+pageSplit);
		
		model.addAttribute("pageSplit",pageSplit);
		model.addAttribute("actualStockStatusCount",actualStockStatusCount);
		model.addAttribute("resultList",actualStockStatusService.getActualStockStatusView(param));
    }
}
